package info

import (
	"github.com/shirou/gopsutil/mem"
	"service/utils"
)

type MemInfo struct {
	Total       uint64  `json:"total"`
	Available   uint64  `json:"available"`
	Used        uint64  `json:"used"`
	Free        uint64  `json:"free"`
	UserPercent float64 `json:"userPercent"`
}

//获取内存信息
func GetMemInfo() (interface{}, error) {
	memdata := MemInfo{}

	v, _ := mem.VirtualMemory()

	//total := utils.HanderUnit(v.Total, NUM_GB,"G")
	//available := utils.HanderUnit(v.Available, NUM_GB,"G")
	//used := utils.HanderUnit(v.Used, NUM_GB,"G")
	//free := utils.HanderUnit(v.Free, NUM_GB,"G")
	//userPercent := fmt.Sprintf("%.2f",v.UsedPercent)

	total := v.Total
	available := v.Available
	used := v.Used
	free := v.Free
	userPercent := v.UsedPercent

	memdata.Total = total
	memdata.Available = available
	memdata.Used = used
	memdata.Free = free
	userPercent = utils.Decimal(userPercent, "2")
	memdata.UserPercent = userPercent

	return memdata, nil
}
